home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / wiredsprites / common files / imagecompressionutilities.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  5.2 KB  |  187 lines

  1. //////////
  2. //
  3. //    File:        ImageCompressionUtilities.h
  4. //
  5. //    Contains:    Image Compression Utilities.
  6. //
  7. //    Written by:    Peter Hoddie, Sean Allen, Chris Flick
  8. //    Revised by:    Tim Monroe
  9. //
  10. //    Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <2>         03/17/00    rtm        moved some things from ImageCompressionUtilities.c to here
  15. //       <1>         03/27/98    rtm        existing file
  16. //
  17. //////////
  18.  
  19.  
  20. #ifndef __IMAGECOMPRESSIONUTILITIES__
  21. #define __IMAGECOMPRESSIONUTILITIES__
  22.  
  23.  
  24. //////////
  25. //
  26. // header files
  27. //
  28. //////////
  29.  
  30. #ifndef __MOVIES__
  31. #include <Movies.h>
  32. #endif
  33.  
  34. #ifndef __COLORPICKER__
  35. #include <ColorPicker.h>
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __ENDIAN__
  43. #include <Endian.h>
  44. #endif
  45.  
  46. #ifndef __IMAGECOMPRESSION__
  47. #include <ImageCompression.h>
  48. #endif
  49.  
  50. #ifndef __QUICKDRAW__
  51. #include <Quickdraw.h>
  52. #endif
  53.  
  54. #ifndef PASCAL_RTN
  55. #define PASCAL_RTN
  56. #endif
  57.  
  58.  
  59. //////////
  60. //
  61. // compiler macros
  62. //
  63. //////////
  64.  
  65. #define BailIf(a, e)                         {if (a)     { err = e; goto bail; }}
  66. #define BailOSErr(a)                         {if ((err = a) != noErr)    goto bail;}
  67. #define BailMemErr(a)                        {a; if ((err = MemError()) != noErr) goto bail;}
  68.  
  69. #if TARGET_OS_WIN32
  70. #define GetPortGrafProcs(a)                    (CQDProcsPtr)a->grafProcs
  71. #define SetPortGrafProcs(a,b)                a->grafProcs=(CGrafPtr)b
  72. #endif
  73.  
  74.  
  75. //////////
  76. //
  77. // constants
  78. //
  79. //////////
  80.  
  81. #define kCompressDepth                        16            // use the Animation compressor at 16 bit depth in these utilities
  82. #define kThreshold                            (255-16)
  83.  
  84. enum {
  85.     kRecoProcInitMsg = 1,                    // message and refcon are valid
  86.     kRecoProcDisposeMsg = 2,                // message and refcon are valid
  87.     kRecoProcGetBoundsMsg = 3,                // message, bounds and refcon are valid. Proc fills in bounds with rectangle to use for compressed image.
  88.     kRecoProcDrawMsg = 4                    // message, bounds, drawingPort, portType and refcon are valid. portType is 'imag' if drawing into
  89.                                             // image GWorld, 'imap' if drawing into hit testing GWorld.
  90. };
  91.  
  92. enum {
  93.     kRecoProcOriginalImageType            =     FOUR_CHAR_CODE('imag'),
  94.     kRecoProcHitTestingImageType        =     FOUR_CHAR_CODE('imap')
  95. };
  96.  
  97.  
  98. //////////
  99. //
  100. // data types
  101. //
  102. //////////
  103.  
  104. // used for compressing QuickDraw pictures with transparency/hittesting
  105. typedef struct {
  106.     PicHandle                    picture;
  107. } PictureCompressProcData;
  108.  
  109. // used for recompressing QuickTime compressed data with transparency/hittesting
  110. typedef struct {
  111.     ImageDescriptionHandle        imageDesc;
  112.     Handle                        imageData;
  113. } CompressedImageCompressProcData;
  114.  
  115. // used for extracting QuickTime compressed image data and description, if any, from a QuickDraw picture
  116. typedef struct {
  117.     CGrafPtr                    tempPort;
  118.     Handle                        data;
  119.     ImageDescriptionHandle        idh;
  120. } extractPictRecord;
  121.  
  122. // low-level callback procedure based routine to compress with/without transparency & hit-testing
  123. typedef PASCAL_RTN OSErr (*CompressDrawProc)( short message, Rect * bounds, GWorldPtr drawingPort, OSType drawingImageType, void * refcon );
  124.  
  125.  
  126. //////////
  127. //
  128. // function prototypes
  129. //
  130. //////////
  131.  
  132. OSErr                                    ExtractCompressData ( PicHandle thePict, Handle *dataOut, ImageDescriptionHandle *idh );
  133. PASCAL_RTN void                            extractStdPix ( PixMap *src, Rect *srcRect, MatrixRecord *matrix, short mode, RgnHandle mask, PixMap *matte, Rect *matteRect, short flags );
  134. static ImageDescriptionHandle            createImageDescription ( CodecType cType, PixMapHandle pixmap );
  135. PASCAL_RTN void                            noDitherBitsProc (BitMap *srcBits, Rect *srcRect, Rect *dstRect, short mode, RgnHandle maskRgn);
  136. static void                                DrawPictureNoDither (PicHandle pic, const Rect *bounds);
  137. static OSErr                            prepareFor16BitCompress (PicHandle *pic);
  138.  
  139. // utilities for compressing from various types of sources
  140. OSErr                                    RecompressWithTransparencyFromProc (
  141.                                                     CompressDrawProc drawProc,
  142.                                                     void * drawProcRefcon, 
  143.                                                     Boolean includeHitTesting,
  144.                                                     RGBColor *keyColor, 
  145.                                                     RgnHandle hitTestRegion,
  146.                                                     ImageDescriptionHandle *idh,
  147.                                                     Handle * imageData );
  148.                                                     
  149. static PASCAL_RTN OSErr                    myPictureCompressDrawProc ( 
  150.                                                     short message,
  151.                                                     Rect * bounds,
  152.                                                     GWorldPtr drawingPort,
  153.                                                     OSType portType,
  154.                                                     void * refcon );
  155.                                                     
  156. static PASCAL_RTN OSErr                    myImageCompressDrawProc (
  157.                                                     short message,
  158.                                                     Rect * bounds,
  159.                                                     GWorldPtr drawingPort,
  160.                                                     OSType portType,
  161.                                                     void * refcon );
  162.  
  163. OSErr                                    RecompressCompressedImageWithTransparency (
  164.                                                     ImageDescriptionHandle originalDesc,
  165.                                                     Handle originalImageData,
  166.                                                     RGBColor *keyColor, 
  167.                                                     RgnHandle limitHitTestRegion,
  168.                                                     ImageDescriptionHandle *idh,
  169.                                                     Handle * imageData );
  170.                                                     
  171. OSErr                                    RecompressPictureWithTransparency (
  172.                                                     PicHandle originalPicture,
  173.                                                     RGBColor *keyColor, 
  174.                                                     RgnHandle limitHitTestRegion,
  175.                                                     ImageDescriptionHandle *idh,
  176.                                                     Handle * imageData );
  177.                                                     
  178. OSErr                                    RecompressPictureFileWithTransparency (
  179.                                                     FSSpec * spec, 
  180.                                                     RGBColor *keyColor, 
  181.                                                     RgnHandle limitHitTestRegion,
  182.                                                     ImageDescriptionHandle *idh,
  183.                                                     Handle * imageData );
  184.                                                     
  185.  
  186. #endif // __IMAGECOMPRESSIONUTILITIES__
  187.